<template>
  <el-row>
    <el-col class="content-header" :span="24">
      <div class="left"><span></span>{{ headerInfo.title }}</div>
      <div class="right" v-if="showRight">
        <el-button class="btn" v-show="showBtn" type="primary" size="small">{{
          headerInfo.rightInfo.btnName
        }}</el-button>
        <el-input
          size="small"
          v-model="iptVal"
          :placeholder="headerInfo.rightInfo.iptMessage"
          class="input-with-select"
          clearable
          @change="getList"
          @clear="getGoodsLists"
        >
          <el-button
            size="small"
            slot="append"
            icon="el-icon-search"
            @click="getList"
          ></el-button>
        </el-input>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import { mapActions } from "vuex";
export default {
  name: "Contentheader",
  props: ["headerInfo"],
  data() {
    return {
      // 是否显示右侧输入框
      showRight: true,
      // 是否显示右侧按钮
      showBtn: true,
      // 输入框的数据
      iptVal: "",
    };
  },
  mounted() {
    // 如果是个人信息路由组件，将右侧输入框隐藏
    if (this.$route.path == "/home/usermessage") {
      this.showRight = false;
    }
    // 如果是个用户管理组件，将右侧按钮隐藏
    if (this.$route.path == "/home/usermanage") {
      this.showBtn = false;
    }
  },
  methods: {
    // 搜索按钮
    getList() {
      // 如果是物品发布页，则搜索物品信息
      if (this.$route.path == "/home/goodissus") {
        this.$store.dispatch("goodissus/getSearchGoodsLists", this.iptVal);
      }
      // 如果是个用户管理页，则搜索用户名
      if (this.$route.path == "/home/usermanage") {
        this.$store.dispatch("usermanage/searchUserLists", this.iptVal);
      }
    },
    ...mapActions("goodissus", ["getGoodsLists"]),
  },
};
</script>

<style lang="less" scoped>
@Headerheight: 60px; //头部高度
.content-header {
  background: #fff;
  line-height: @Headerheight;
  .left {
    float: left;
    margin-left: 20px;
    span {
      padding: 0 1px;
      background: #265bcd;
      margin-right: 5px;
    }
  }
  .right {
    float: right;
    margin-right: 30px;
    width: 270px;
    height: @Headerheight;
    position: relative;
    .el-input {
      width: 200px;
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
    }
    .btn {
      margin-right: 10px;
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
    }
  }
}
.el-button {
  outline: none;
}
</style>
